package com.dcy.iterator;

import java.util.Iterator;

/**
 * @Author：dcy
 * @Description:
 * @Date: 2021/1/28 9:27
 */
public class ComputerCollegeIterator implements Iterator<Department> {

    /**
     * 表示Department是以数组方式存储
     */
    Department[] departments;
    /**
     * 遍历的位置
     */
    int position = 0;

    public ComputerCollegeIterator(Department[] departments) {
        this.departments = departments;
    }

    /**
     * 判断是否还有下一个元素
     *
     * @return
     */
    @Override
    public boolean hasNext() {
        if (position >= departments.length || departments[position] == null) {
            return false;
        }
        return true;
    }

    @Override
    public Department next() {
        Department department = departments[position];
        position += 1;
        return department;
    }

    /**
     * 空实现
     */
    @Override
    public void remove() {

    }
}
